<template>
  <div>
<!--    添加按钮-->
    <div class="add" v-if="state1" v-show="state">
      <el-button type="primary" plain @click="add">添加按钮</el-button>
    </div>
<!--    添加按钮弹出框-->
    <div v-if="!state1" class="add1">
      <el-form ref="form" :model="form1" label-width="80px" style="width: 300px">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="用户类型" style="width: 200px">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="状态" style="width: 100px">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button @click="quxiao2">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
<!--内容框-->
    <div v-show="state" v-if="state1">
  <el-table
      :data="tableData"
      style="width: 100%">
    <el-table-column
        align="center"
        label="用户名"
        width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.name }}</span>
      </template>
    </el-table-column>
    <el-table-column
        align="center"
        label="电话"
        width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.phone }}</span>
      </template>
    </el-table-column>
    <el-table-column
        align="center"
        label="用户类型"
        width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.type }}</span>
      </template>
    </el-table-column>
    <el-table-column
        align="center"
        label="状态"
        width="180">
      <template slot-scope="scope">
        <span style="margin-left: 10px">{{ scope.row.state }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
            size="mini"
            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    </div>
    <!--    弹出编辑框表单-->
    <div v-show="!state" class="add1">
    <el-form ref="form" :model="form" label-width="80px" style="width: 400px">
      <el-form-item label="用户名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>

      <el-form-item label="用户类型">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="电话" style="width: 200px">
        <el-input  v-model="form.desc"></el-input>
      </el-form-item>
      <el-form-item label="状态" style="width: 50px">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">确定修改</el-button>
        <el-button @click="quxiao">取消</el-button>
      </el-form-item>
    </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name:'test1',
  data() {
    return {
      state1:true,
      state:true,
      // 编辑
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: '',
      },
    //  添加
      form1: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    ,
      tableData: [{
        phone: '2016-05-02',
        name: '王小虎',
        type: '......',
        state:'0'
      },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        }
      ,
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },
        {
          phone: '2016-05-02',
          name: '王小虎',
          type: '......',
          state:'0'
        },

        ]
    }
  },
  methods: {
    handleEdit(index, row) {
      console.log(index, row);
      this.state = false
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    onSubmit() {
      console.log('submit!');
    },
    quxiao(){
      this.state = true
    },
    add(){
      this.state1 = false
    },
    quxiao2(){
      this.state1 = true
    }
  }
}
</script>
<style scoped>
.add{
  position: relative;
  top: 60px;
  left: 800px;
  width: 100px;
  height: 50px;
  z-index: 1000;
}
.add1{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
}
</style>
